﻿
Pages_Report_ReportUserAssets = new function () {
    this.ObjSearch = {
        AccountId: -1,      
        AccountName: ''      
    };
    

    this.m_objPageUserAssets = new VtcPaging("divUserAssetsPaging", "Pages_Report_ReportUserAssets.bindData", "pagingCss", 10, CONSTANT.PAGE_DISPLAY);
    this.getOptionSearch = function() {
        this.ObjSearch.AccountId = parseInt($("#txtAccountId").val());
        this.ObjSearch.AccountId = this.ObjSearch.AccountId > 0 ? this.ObjSearch.AccountId : -1;        
        
        this.ObjSearch.TypeId = $("#ddlTypeId").val();

        this.ObjSearch.AccountName = $("#txtAccountName").val();
        this.ObjSearch.FromDate = $("#txtFromDate").val();
        this.ObjSearch.ToDate = $("#txtToDate").val();
    };
    this.documentReady = function () {
        this.getOptionSearch();
        this.bindData(1, this.m_objPageUserAssets.pageSize);
    };

    this.bindData = function (_cur, _ps) {
        Loading.showProcess();        
        $.ajax({
            type: "GET",
            url: "/handler/HandlerReport.ashx",
            data: {
                accountId: this.ObjSearch.AccountId, accountName: this.ObjSearch.AccountName,
                currentPage: _cur, pageSize: _ps, t: "rptUserAssets"
            },
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            cache: false,
            success: function (data) {
                Pages_Report_ReportUserAssets.processData(data, _cur);
                Loading.closeProcess();
            }
        });

    };

    this.processData = function (data, _cur) {
        $("#spTotalAdmin").html('(' + data.TotalRecord.toString() + ')');
        
        $("#tdTotalAuIn").html(COMMON.formatMoney(data.TotalReceiveAu));
        $("#tdTotalAgIn").html(COMMON.formatMoney(data.TotalReceiveAg));
        $("#tdTotalAuToMoney").html(COMMON.formatMoney(data.TotalAuOut));
        
        $("#tdTotalAuPlay").html(COMMON.formatMoney(data.TotalAuPlay));
        $("#tdTotalAuBonus").html(COMMON.formatMoney(data.TotalAuBonus));
        $("#tdTotalAgPlay").html(COMMON.formatMoney(data.TotalAgPlay));        
        $("#tdTotalAgBonus").html(COMMON.formatMoney(data.TotalAgBonus));
        
        $("#tdTotalAuNow").html(COMMON.formatMoney(data.CurrentAu));
        $("#tdTotalAgNow").html(COMMON.formatMoney(data.CurrentAg));
        
        $("#tdTotalAgToAu").html(COMMON.formatMoney(data.TotalAgToAu));
        $("#tdTotalAuFromAg").html(COMMON.formatMoney(data.TotalAuFromAg));
        
        
        $("#divUserAssets").setTemplateURL("/Template/Pages/Report/rptUserAssets.htm");
        $("#divUserAssets").processTemplate(data);
        Pages_Report_ReportUserAssets.setStyleRow("#divUserAssets");
        Pages_Report_ReportUserAssets.m_objPageUserAssets.bindPaging(_cur, data.TotalRecord);
        if (data.TotalRecord <= Pages_Report_ReportUserAssets.m_objPageUserAssets.pageSize) {
            $("#divUserAssetsPaging").attr('style', 'display:none');
        }
        else {
            $("#divUserAssetsPaging").attr('style', 'display:block');
        }
    };
   
    $("#btnSearch").live('click', function () {
        Pages_Report_ReportUserAssets.documentReady();
        
    });

   
    this.setStyleRow = function (m_selParent) {
        var m_stt = 0;
        $('#divItem', m_selParent).each(function () {
            m_stt++;
            if ((m_stt % 2) == 0) {
                $(this.parentNode).addClass('even');
            }
            else {
                $(this.parentNode).addClass('odd');
            }
        });
    };       
}